import { httpRequest } from "../httpRequest"
import type { IRes, IResWithPage } from "../types"
import type { IPaper } from "@shared/types/paper"

export const paperApi = {
    getPaperList(params: {
        page?: number;
        pageSize?: number;
        status?: string;
        creator?: string;
        keyword?: string;
    }): IResWithPage<IPaper[]> {
        return httpRequest.get('/api/v1/paper/list', { params })
    },
    getPaperDetail(id: string): IRes<IPaper> {
        return httpRequest.get('/api/v1/paper/detail', {
            params: { id }
        })
    },
    createPaper(data: Omit<IPaper, '_id' | 'create_time' | 'creator' | 'total_score'>): IRes<IPaper> {
        return httpRequest.post('/api/v1/paper/create', data)
    },
    updatePaper(data: Partial<IPaper> & { id: string }): IRes<IPaper> {
        return httpRequest.post('/api/v1/paper/update', data)
    },
    deletePaper(id: string): IRes<null> {
        return httpRequest.post('/api/v1/paper/delete', { id })
    },
    batchDeletePaper(ids: string[]): IRes<{ deletedCount: number }> {
        return httpRequest.post('/api/v1/paper/delete', { ids })
    },
    previewPaper(id: string): IRes<IPaper & { statistics: any }> {
        return httpRequest.get('/api/v1/paper/preview', {
            params: { id }
        })
    }
}